package com.pj.xfxh.thread;

import okhttp3.WebSocket;

public class MyThread extends Thread {
    private WebSocket webSocket;
    private String requestJson;
    private Boolean wsCloseFlag;

    public MyThread(WebSocket webSocket, String requestJson, Boolean wsCloseFlag) {
        this.webSocket = webSocket;
        this.requestJson = requestJson;
        this.wsCloseFlag = wsCloseFlag;
    }

    public void run() {
        try {
            webSocket.send(requestJson);
            // 等待服务端返回完毕后关闭
            while (true) {
                Thread.sleep(200);
                if (wsCloseFlag) {
                    break;
                }
            }
            webSocket.close(1000, "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}